package cn.yt.hospital.controller;

import cn.yt.hospital.entity.Doctor;
import cn.yt.hospital.service.IDoctorService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yangtao
 * @since 2023-03-01
 */
@Controller
@RequestMapping("/hospital/doctor")
public class DoctorController {
    @Autowired
    private IDoctorService iDoctorService;

    @RequestMapping("/list")
    public String list(Model model){
        List<Doctor> allDoctor = iDoctorService.getAllDoctor();
        System.out.println(allDoctor);
        model.addAttribute("page",allDoctor);
        return "doctor";
    }

    @PostMapping("/add")
    public String add(Doctor doctor){
        iDoctorService.save(doctor);
        return "redirect:list";
    }

    @RequestMapping("/del")
    public String delete(@RequestParam("did")Integer did){
        iDoctorService.removeById(did);
        return "redirect:list";
    }

    @RequestMapping("/up")
    public String up(@RequestParam("did") Integer did, Model model) {
        Doctor doctor = iDoctorService.getById(did);
        model.addAttribute("doctor", doctor);
        return "up";
    }
    @RequestMapping("/up1")
    public String upDog1(Doctor doctor){
        iDoctorService.updateById(doctor);
        return "redirect:list";
    }
}
